<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            border: 1px solid;
        }
    </style>
</head>
<body>
    <!-- 封装一个十六进制的随机颜色 函数  #fff111 -->
    <div id="color"></div>
</body>
<script>
    (function () {
        function ranColor() {
            let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', 'f'];
            let colorStr = '#';
            for (let i = 0; i < 6; i++) {
                colorStr += arr[parseInt(Math.random() * 16)];
            }    
            return colorStr;
        }


        //实验效果
        let color = document.getElementById('color');
        color.onclick = function () {
            color.style.backgroundColor = ranColor();
            console.log(ranColor());
        }






    })();
</script>
</html>